home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / _archvrs / unix / unzip51 / amiga / filedate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-11  |  5.3 KB  |  194 lines

  1. /* filedate.c (originally utime.c), by Paul Wells.  Modified by John Bush
  2.  *  and others (see also sendpkt() comments, below); NewtWare SetFileDate()
  3.  *  clone cheaply ripped off from utime().
  4.  */
  5.  
  6. /* HISTORY/CHANGES
  7.  * Created:  2 Sep 92, by Cave "Greg Roelofs" Newt 
  8.  * Incorporated into UnZip 5.1 -- J.Bush, 6 Sep 92:
  9.  *   Interlude "FileDate()" defined, which calls or redefines  
  10.  *   SetFileDate() depending upon AMIGADOS2 definition.
  11.  */
  12.  
  13. /* DESCRIPTION
  14.  * This routine chooses between 2 methods to set the file date on AMIGA.
  15.  * Since AmigaDOS 2.x came out, SetFileDate() was available in ROM (v.36
  16.  * and higher).  Under AmigaDOS 1.3.x (less than v.36 ROM), SetFileDate()
  17.  * must be accomplished by constructing a message packet and sending it
  18.  * to the file system handler of the file to be stamped.
  19.  *
  20.  * If AMIGADOS2 is defined, then ROM version of SetFileDate() is called.
  21.  * If AMIGADOS2 is NOT defined, then substitute "equivalent" code prevails.
  22.  * If AMIGA is undefined, don't compile (error... AMIGADOS2 probably defined
  23.  * on non-Amiga platform).
  24.  */
  25.  
  26. #include <string.h>
  27. #include <time.h>
  28. #include <errno.h>
  29.  
  30. #include <exec/types.h>
  31. #include <exec/memory.h>
  32. #include <libraries/dos.h>
  33. #include <libraries/dosextens.h>
  34. #include <proto/exec.h>
  35. #include <proto/dos.h>
  36.  
  37. LONG FileDate(char *filename, struct DateStamp *pDate);
  38.  
  39. extern int _OSERR;
  40.  
  41. #ifndef SUCCESS
  42. #  define SUCCESS (-1L)
  43. #  define FAILURE 0L
  44. #endif
  45.  
  46.  
  47. /* ------------------------------------------------------------------- */
  48. #ifdef AMIGADOS2
  49. /* ------------------------------------------------------------------- */
  50.  
  51. LONG SetFileDate(char *filename, struct DateStamp *pDate);
  52.  
  53. LONG FileDate(filename, pDate)
  54.     char *filename;
  55.     struct DateStamp *pDate;
  56. {
  57.     return (SetFileDate(filename,pDate));  /* native routine at 2.0+ */
  58. }
  59.  
  60. /* ------------------------------------------------------------------- */
  61. #else /* !AMIGADOS2 */
  62. #ifdef AMIGA
  63. /* ------------------------------------------------------------------- */
  64.  
  65. LONG sendpkt(struct MsgPort *pid, LONG action, LONG *args, LONG nargs);
  66.  
  67. LONG FileDate(filename, pDate)
  68.     char *filename;
  69.     struct DateStamp *pDate;
  70. {
  71.     struct MsgPort *taskport;
  72.     struct FileLock *dirlock, *lock;
  73.     struct FileInfoBlock *fib;
  74.     LONG argv[4];
  75.     UBYTE *ptr;
  76.     long ret;
  77.  
  78.  
  79.     if( !(taskport = (struct MsgPort *)DeviceProc(filename)) )
  80.     {
  81.         errno = ESRCH;          /* no such process */
  82.         _OSERR = IoErr();
  83.         return FAILURE;
  84.     }
  85.  
  86.     if( !(lock = (struct FileLock *)Lock(filename,SHARED_LOCK)) )
  87.     {
  88.         errno = ENOENT;         /* no such file */
  89.         _OSERR = IoErr();
  90.         return FAILURE;
  91.     }
  92.  
  93.     if( !(fib = (struct FileInfoBlock *)AllocMem(
  94.         (long)sizeof(struct FileInfoBlock),MEMF_PUBLIC|MEMF_CLEAR)) )
  95.     {
  96.         errno = ENOMEM;         /* insufficient memory */
  97.         UnLock((BPTR)lock);
  98.         return FAILURE;
  99.     }
  100.  
  101.     if( Examine((BPTR)lock,fib)==FAILURE )
  102.     {
  103.         errno = EOSERR;         /* operating system error */
  104.         _OSERR = IoErr();
  105.         UnLock((BPTR)lock);
  106.         FreeMem((char *)fib,(long)sizeof(*fib));
  107.         return FAILURE;
  108.     }
  109.  
  110.     dirlock = (struct FileLock *)ParentDir((BPTR)lock);
  111.     ptr = (UBYTE *)AllocMem(64L,MEMF_PUBLIC);
  112.     strcpy((ptr+1),fib->fib_FileName);
  113.     *ptr = strlen(fib->fib_FileName);
  114.     FreeMem((char *)fib,(long)sizeof(*fib));
  115.     UnLock((BPTR)lock);
  116.  
  117.     /* now fill in argument array */
  118.  
  119.     argv[0] = NULL;
  120.     argv[1] = (LONG)dirlock;
  121.     argv[2] = (LONG)&ptr[0] >> 2;
  122.     argv[3] = (LONG)pDate;
  123.  
  124.     errno = ret = sendpkt(taskport,34L,argv,4L);
  125.  
  126.     FreeMem(ptr,64L);
  127.     UnLock((BPTR)dirlock);
  128.  
  129.     return SUCCESS;
  130.  
  131. } /* FileDate() */
  132.  
  133. /*  sendpkt.c
  134.  *  by A. Finkel, P. Lindsay, C. Sheppner
  135.  *  returns Res1 of the reply packet
  136.  */
  137. /*
  138. #include <exec/types.h>
  139. #include <exec/memory.h>
  140. #include <libraries/dos.h>
  141. #include <libraries/dosextens.h>
  142. #include <proto/exec.h>
  143. #include <proto/dos.h>
  144. */
  145.  
  146. LONG sendpkt(pid,action,args,nargs)
  147. struct MsgPort *pid;           /* process identifier (handler message port) */
  148. LONG action,                   /* packet type (desired action)              */
  149.      *args,                    /* a pointer to argument list                */
  150.      nargs;                    /* number of arguments in list               */
  151. {
  152.  
  153.     struct MsgPort *replyport;
  154.     struct StandardPacket *packet;
  155.     LONG count, *pargs, res1;
  156.  
  157.     replyport = (struct MsgPort *)CreatePort(0L,0L);
  158.     if( !replyport ) return(NULL);
  159.  
  160.     packet = (struct StandardPacket *)AllocMem(
  161.             (long)sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR);
  162.     if( !packet )
  163.     {
  164.         DeletePort(replyport);
  165.         return(NULL);
  166.     }
  167.  
  168.     packet->sp_Msg.mn_Node.ln_Name  = (char *)&(packet->sp_Pkt);
  169.     packet->sp_Pkt.dp_Link          = &(packet->sp_Msg);
  170.     packet->sp_Pkt.dp_Port          = replyport;
  171.     packet->sp_Pkt.dp_Type          = action;
  172.  
  173.     /* copy the args into the packet */
  174.     pargs = &(packet->sp_Pkt.dp_Arg1);      /* address of 1st argument */
  175.     for( count=0; count<nargs; count++ )
  176.         pargs[count] = args[count];
  177.  
  178.     PutMsg(pid,(struct Message *)packet);   /* send packet */
  179.  
  180.     WaitPort(replyport);
  181.     GetMsg(replyport);
  182.  
  183.     res1 = packet->sp_Pkt.dp_Res1;
  184.  
  185.     FreeMem((char *)packet,(long)sizeof(*packet));
  186.     DeletePort(replyport);
  187.  
  188.     return(res1);
  189.  
  190. } /* sendpkt() */
  191.  
  192. #endif /* AMIGA */
  193. #endif /* ?AMIGADOS2 */
  194.